/**
 * 拜访人
 * Created by wenchuan.li on 2018/7/3 13:06.
 */
define(function () {

    var self,
        app = win.app,
        pageParameters
    ;

    var Bfr = app.Module.extend({

        init: function () {
            self = this;
            self._super({
                _readyBefore: function () {
                    pageParameters = self._pageParameters;
                },
                _refreshAutoInit: true //自动加载刷新控件
            }, win);
        },
        _initRefresh: function () { // 实例化刷新组件
            if (self._refreshIds.length == 0) {
                self._refreshIds = ['scroll1'];
            }
            this._super(win);
        },
        _refreshCb: function (goods) {// 刷新组件回调函授
            var _super = this._super;
            app.ajax({
                xurl: "api/wx/gwat161/gwat161Bfr01",
                xdata: {
                    page:goods.page+1,
                    limit: goods.limit,
                    GWBIID: pageParameters.GWBIID,
                    GWBINAME:pageParameters.GWBINAME
                },
                cb: function (result) {
                    if (result.ok) {
                        _super({
                            obj: goods,
                            data: result.data.data,
                            nodata: '无拜访人信息...'
                        });
                    }
                }
            });
        },
        _lazy: function () {
            this._super();
            app.taps.call(win,[
                {
                    o:'addBtn',
                    cb:function (e) {
                        app.openPage({
                            src: "hn-bfjltb/bfr-add.html",
                            args: {
                                GWBIID: pageParameters.GWBIID,
                                GWBINAME:pageParameters.GWBINAME,
                                cb: function (v) {
                                    pageParameters.cb(v);
                                    self._refresh();
                                }
                            }
                        });
                    }
                },
                {
                    o:'backBtn',
                    cb:function () {
                        app.back(1);
                    }
                }
            ]);
        },
        _ready: function () {
            Vue.component('bfritem', {
                template: app.getByid(doc, 'bfritem-template'),
                props: {
                    model: Array
                },
                methods: {
                    select:function (v) {
                        pageParameters.cb(v);
                        app.back(1);
                    }
                }
            });
        }
    });

    new Bfr();

});